package nsoft.swing.engine;

import java.awt.Color;
import java.awt.Component;
import java.util.Arrays;
import java.util.StringTokenizer;

import nsoft.util.BeanUtilities;

public final class PropertySetter {

	private static String[] colors = { "COLOR", "FOREGROUND", "BACKGROUNG" };

	public static void setProperties(Component component, String[] properties) {
		for (String input : properties) {
			PropertySetter.setProperty(component, input);
		}
	}

	public static void setProperty(Component component, String propertyValue) {
		StringTokenizer tokenizer = new StringTokenizer(propertyValue, ":");
		String property = tokenizer.nextToken();
		String value = tokenizer.nextToken();
		if (Arrays.binarySearch(colors, property.toUpperCase()) > -1) {
			PropertySetter.setColor(component, property, value);
		}

	}

	private static void setColor(Component component, String property,
			String value) {
		BeanUtilities.setProperty(component, property, Color.decode(value));
	}
}
